package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/12 13:17
 */
public class M0503 {

    // https://leetcode-cn.com/problems/reverse-bits-lcci/
    public static int reverseBits(int num) {
        int max = 0;
        int reverse = 0;
        int current = 0;
        // 从右往左看
        for (int i = 0; i < 32; i++) {
            if ((num & 1) == 1) {
                current++;
                reverse++;
            } else {
                reverse = current + 1;
                current = 0;
            }
            if (reverse > max) max = reverse;
            num >>= 1;
        }
        return max;
    }

    // for test
    public static void main(String[] args) {
        int num = 7;
        System.out.println(reverseBits(num));

    }

}
